#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for(register int i = (a);i <= (b);++i)
#define per(i,a,b) for(register int i = (a);i >= (b);--i) 
#define mkp std::make_pair
typedef long long ll;
typedef unsigned long long ull;
using std::string;using std::cin;using std::cout;
inline bool cmp(int x,int y){return x < y;}

const int N = 1e6+9;
const int inf = 1e9+9;
const double eps = 1e-7;
int _,n,m,a[2*N],map[1100][1100],ans,cnt;
std::priority_queue< std::pair<int,int> > q;
bool node[1100];

int head[2*N],ver[2*N],next[2*N],edge[2*N],tot;
inline void link(int x,int y,int z){ver[++tot] = y , edge[tot] = z , next[tot] = head[x] , head[x] = tot;}

int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef LOCAL //use "g++ xxx.cpp -DLOCAL"
        freopen("in.in", "r", stdin);
    #endif
    cin >> n;
    rep(i,1,n) rep(j,1,n) cin >> map[i][j];
    rep(i,1,n) rep(j,1,n) if(i != j) link(i,j,map[i][j]);
    while(q.size()) q.pop();
    node[1] = true , cnt = 1;
    for(int i = head[1];i;i = next[i]) q.push(mkp(-edge[i],i));
    while(q.size() || cnt < n){
        std::pair<int,int> now = q.top(); q.pop();
        if(node[ ver[now.second] ]) continue;
        ans -= now.first , node[ ver[now.second] ] = true , ++cnt;
        for(int i = head[ ver[now.second] ];i;i = next[i]) if(!node[ ver[i] ]) q.push(mkp(-edge[i],i));
    }
    cout << ans << "\n";
    return 0;
}